﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Helper;

public partial class Admin_Config : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Config c = ConfigHelper.LoadConfig();
            txtNumberArtifacts.Text = c.SoVatToiDa.ToString();
            txtSubNumbeImage.Text = c.SoAnhToiDa.ToString();
            txtNumberMuseumHightLight.Text = c.SoBaoTangToiDa.ToString();
            chkLienhe.Checked = c.thongtinlienhe;
            txtNguoidaidien.Text = c.NguoiDaiDien;
            txtDiachi.Text = c.DiaChiNguoiDaiDien;
            txtDienthoai.Text = c.DienThoaiNguoiDaiDien;
            txtEmail.Text = c.Email;
            txtGioithieu.Text = c.KichThuocAnhGioiThieu;
            txtBosuutap.Text = c.KichThuocAnhSuuTap;
            txtGiaoluu.Text = c.KichThuocAnhGiaoLuu;
            txtSandaugia.Text = c.KichThuocAnhSanDauGia;
            if (c.NguoiDatThoiGianGiaoLuu == "admin")
                ddlgiaoluutime.SelectedIndex = 1;
            else
                ddlgiaoluutime.SelectedIndex = 0;
            txtSongayGiaoluu.Text = c.SoNgayGiaoLuu.ToString();

            if (c.NguoiDatThoiGianTimKiemQuanTam == "admin")
                dropTimwaitType.SelectedIndex = 2;
            if (c.NguoiDatThoiGianTimKiemQuanTam == "nst")
                dropTimwaitType.SelectedIndex = 1;
            else
                dropTimwaitType.SelectedIndex = 0;
            txtMaxTimeWait.Text = c.SoNgayTimKiemQuanTam.ToString();

            if (c.NguoiDatThoiGianDauGia == "admin")
                dropAuctionTime.SelectedIndex = 2;
            else if (c.NguoiDatThoiGianDauGia == "nst")
                dropAuctionTime.SelectedIndex = 1;
            else
                dropAuctionTime.SelectedIndex = 0;
            txtMaxDay.Text = c.SoNgayDauGia.ToString();

            txtAuctionCost.Text = c.PhiDauGia;
            txtAuctionIndex.Text = c.ChongSpamDauGia.ToString();
            txtInterestedCount.Text = c.SoNguoiQuanTam.ToString();
            txtPhiGiaohang.Text = c.PhiGiaoHang.ToString();
            if (c.NguoiTraPhi == 1)
                rdoNguoimua.Checked = true;
            else if (c.NguoiTraPhi == 2)
                rdoNguoiban.Checked = true;

            txtChuyenTien.Text = c.GiaoDichChuyenTien.ToString();
            if (c.KieuChuyenTien == 1)
                rdoBQT.Checked = true;
            else if (c.KieuChuyenTien == 2)
                rdoTructiep.Checked = true;
            else
                rdoBQT.Checked = true;

            txtNoExchange.Text = c.MessageThongBaoKhiYeuCauGiaoLuu;
            txtInfoNewsEvent.Text = c.TomTatMucTinBaiSuKien;
        }
    }
    protected void lnkClose_Click(object sender, EventArgs e)
    {
        
    }
    protected void lnkSave_Click(object sender, EventArgs e)
    {
        Config c = ConfigHelper.LoadConfig();
        c.SoVatToiDa = Util.Convert(txtNumberArtifacts.Text);
        c.SoAnhToiDa = Util.Convert(txtSubNumbeImage.Text);
        c.SoBaoTangToiDa = Util.Convert(txtNumberMuseumHightLight.Text);
        c.thongtinlienhe = chkLienhe.Checked;
        c.NguoiDaiDien = txtNguoidaidien.Text;
        c.DiaChiNguoiDaiDien = txtDiachi.Text;
        c.DienThoaiNguoiDaiDien = txtDienthoai.Text;
        c.Email = txtEmail.Text;
        c.KichThuocAnhGioiThieu = txtGioithieu.Text;
        c.KichThuocAnhSuuTap = txtBosuutap.Text;
        c.KichThuocAnhGiaoLuu = txtGiaoluu.Text;
        c.KichThuocAnhSanDauGia = txtSandaugia.Text;
        if (ddlgiaoluutime.SelectedValue == "0")
            c.NguoiDatThoiGianGiaoLuu = "member";
        else if (ddlgiaoluutime.SelectedValue == "1")
            c.NguoiDatThoiGianGiaoLuu = "admin";
        else
            c.NguoiDatThoiGianGiaoLuu = "admin";
        c.SoNgayGiaoLuu = Util.Convert(txtSongayGiaoluu.Text);
        if (dropTimwaitType.SelectedValue == "2")
            c.NguoiDatThoiGianTimKiemQuanTam = "admin";
        else if (dropTimwaitType.SelectedValue == "1")
            c.NguoiDatThoiGianTimKiemQuanTam = "nst";
        else
            c.NguoiDatThoiGianTimKiemQuanTam = string.Empty;
        c.SoNgayTimKiemQuanTam = Util.Convert(txtMaxTimeWait.Text);

        if (dropAuctionTime.SelectedValue == "2")
            c.NguoiDatThoiGianDauGia = "admin";
        else if (dropAuctionTime.SelectedValue == "1")
            c.NguoiDatThoiGianDauGia = "nst";
        else
            c.NguoiDatThoiGianDauGia = string.Empty;
        c.SoNgayDauGia = Util.Convert(txtMaxDay.Text);

        c.PhiDauGia = txtAuctionIndex.Text;
        c.ChongSpamDauGia = Util.Convert(txtAuctionIndex.Text);
        c.SoNguoiQuanTam = Util.Convert(txtInterestedCount.Text);
        c.PhiGiaoHang = Util.Convert(txtPhiGiaohang.Text);

        if (rdoNguoimua.Checked == true)
            c.NguoiTraPhi = 1;
        else if (rdoNguoiban.Checked == true)
            c.NguoiTraPhi = 2;

        if (rdoBQT.Checked == true)
            c.KieuChuyenTien = 1;
        else if (rdoTructiep.Checked == true)
            c.KieuChuyenTien = 2;

        c.GiaoDichChuyenTien = Util.Convert(txtChuyenTien.Text);
        c.MessageThongBaoKhiYeuCauGiaoLuu = txtNoExchange.Text;
        c.TomTatMucTinBaiSuKien = txtInfoNewsEvent.Text;
        ConfigHelper.Save(c);
    }
}